HAL NAND migration: List of applicable concepts

This section provides information about the HAL NAND applicable architecture concepts.

Concepts for NAND

Concept

Description

Separation of initialization and configuration functions

Split HAL_NAND_Init() into init and multiple config functions:

  • HAL_NAND_Init(): initializes the NAND handle and associate an instance.

  • HAL_NAND_SetConfig(), HAL_NAND_SetConfigMemory(), HAL_NAND_SetConfigDevicePartition() and HAL_NAND_SetConfigDevicePartitionONFI() functions configure the NAND according to the user parameters.

Removal and conversion of init structure to configuration structure

New configuration structures have been introduced:

  • hal_nand_config_t: FMC parameters,

  • hal_nand_memory_config_t: memory parameters,

  • hal_nand_partition_config_t: memory partition parameters.

Renaming of the handle structure

The handle structure NAND_HandleTypeDef has been renamed to hal_nand_handle_t.

Renaming unitary init structures

The init structure NAND_InitTypeDef is no longer available, it has been replaced by multiple configuration structures:

  • hal_nand_config_t

  • hal_nand_memory_config_t

  • hal_nand_partition_config_t

Remove MspInit and MspDeInit callbacks

The HAL_NAND_MspInit() and HAL_NAND_MspDeInit() are no longer available and have been replaced by a user sequence to initialize and configure the NAND.

Individual callback registration APIs replace global register and unregister functions

The callback registration is now handled by specific functions for each NAND event.

Revised and optimized HAL state machine

The state machine has been reworked to ensure transitions of the peripheral functional states.

Revised and optimized HAL API status returns

The HAL NAND functions were updated to return:

  • HAL_INVALID_PARAM: in case of a NULL p_config structure pointer.

  • HAL_TIMEOUT: in case of a user timeout.

  • HAL_OK: in case of a successfully completed operation.

Replaced TypeDef suffix with _t in type names

All TypeDef parts of the HAL NAND driver have been removed and replaced by _t.

Replaced nonmodifiable pointers with const keywords

Const keywords have been added to non-modifiable pointers to ensure that either the pointer itself or the data it points to cannot be modified. This enhances code safety and readability, prevents unintended modifications, and renders code more robust and maintainable.

Assertion implementation and usage in HAL1

The ASSERT_DBG_STATE and ASSERT_DBG_PARAM macros are used to check the parameters and state of the HAL NAND driver.

Rename LL core drivers to stm32_ppp_core.h/.c to avoid confusion with user LL drivers.

The core driver name has been changed from stm32_ll_fmc.h/.c to stm32tnxx_fmc_core.h/.c.

Add HAL PPP Services for Drivers with Handle to Retrieve Corresponding Peripheral Clock Frequency.

HAL NAND provides new API to retrieve clock frequency HAL_NAND_GetClockFreq().

Replace Finite Parameter Defines (Including PPP Instances) with Enum Types at HAL Levels.

Convert finite parameters, (including instances) into enumerated types (enums) at the HAL level. This improves code readability, maintainability, and type safety.

Add HAL_PPP Prefix to All HAL Peripheral APIs (Defines, Macros, Types, and Functions).

All HAL NAND functions start with HAL_NAND. All HAL NAND enum and struct start with hal_nand.


Other HAL NAND changes

Concept

Consideration

Support ONFI (Open NAND Flash Interface)

The NAND driver is ONFI compliant. ONFI is the default command interface. As a consequence :

  • All mandatory commands are supported.

  • Read and program APIs now perform single-page read/program operations only (no more multi-page operations).

  • The following ONFI related commands are added : ONFI detect, read parameter page, change read column, change write column.

  • Selected optional ONFI commands are supported according to needs, including copy back read and copy back program.

  • The initial non-ONFI (Legacy) NAND flash devices commands are subset of the ONFI, no dedicated legacy APIs are required.

Merge 8 and 16 bits program and read APIs into a single program and read interfaces

In HAL 1, there are two sets APIs depending on data width:

  • HAL_NAND_xxxx_8b

  • HAL_NAND_xxxx_16b

In HAL 2, a single API is provided by functionality to handle processes for 8-bit and 16-bit APIs.

Replace Ready/Busy interrupt handling with an internal status check sequence

In HAL 1, three interrupts are generated on Ready/Busy signal:

  • High level, rising edge, falling edge

In HAL 2, these interrupts are removed from the driver as the device status reads are handled internally within process APIs.

Make the NAND structures and defines available in HAL_NAND header file instead of fmc core header file.

All HAL NAND public APIs and structures are available in stm32xx_hal_nand.h.

Improves API discoverability and decouples from fmc core ( stm32xx_fmc_core.h).

Provide timing parameters in time units (ns, ms), instead of clock cycles.

Offers user-friendly units and simplifies configuration.